﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using QLCHBANGIAY.DATA;
using QLCHBANGIAY.BUSINESS;

namespace QuanLyBanGiay
{
    public partial class AM_QLSP : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //List<Product> lists = new List<Product>();
            //lists = ProductServices.Product_GetByAll();
            //textthu.DataSource = lists;
            //textthu.DataBind();
            Load_LuoiSP();
            Load_LoaiSP();
        }
        private void Load_LoaiSP()
        {
            try
            {
                List<Category> lists = new List<Category>();
                lists = CategoryServices.Category_GetByTop("100", "", "");
                cboLoai.DataSource = lists;
                cboLoai.DataTextField = "name";
                cboLoai.DataValueField = "id";
                cboLoai.DataBind();
                cboLoai.Items.Insert(0, new ListItem("Chọn loại ", "-1"));
            }
            catch (Exception ex)
            {
                return;
            }

        }
        private void Load_LuoiSP()
        {
            try
            {
                List<Product> lists = new List<Product>();
                lists = ProductServices.Product_GetByTop("1000", "", "");
                gvSP.DataSource = lists;
                gvSP.DataBind();
            }
            catch (Exception ex)
            {
                return;
            }


        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void gvSP_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void btnTimKiem_Click(object sender, EventArgs e)
        {

            if (txtTenSP.Text == null)
            {
                Load_LuoiSP();
            }
            else
            {
                List<Product> lists = new List<Product>();
                string key = txtTenSP.Text;
                lists = ProductServices.Product_GetByTop("1000", "name like N'%" + key + "%'", "");

                gvSP.DataSource = lists;
                gvSP.DataBind();
            }

        }

        protected void btnThemSP_Click(object sender, EventArgs e)
        {
            Response.Redirect("AM_Chitietsanpham.aspx");
        }

        protected void lnkEdit_Click(object sender, EventArgs e)
        {

        }

        protected void gvSP_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {

        }

    }
}